package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.es.service.EsDocService;
import com.bawei.system.domain.vo.EsDocInsertVo;
import com.bawei.system.domain.vo.EsDocQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiZizheng
 */
@RestController
@RequestMapping("/esDoc")
@Api(tags = "Es文档管理")
public class EsDocController {

    @Autowired
    private EsDocService esDocService;

    @PostMapping("/batchInsertDocs")
    @ApiOperation("批量插入文档")
    public R<Boolean>  batchInsertDocs(@RequestBody List<EsDocInsertVo> esDocInsertVo){
        return esDocService.batchInsertDocs(esDocInsertVo);
    }

    @PostMapping("/queryDocs")
    @ApiOperation("根据传入条件查询Es的文档数据")
    public R  queryDocs(@RequestBody EsDocQueryVo esDocInsertVo){
        return esDocService.queryDocs(esDocInsertVo);
    }

    @PostMapping("/deleteDocs")
    @ApiOperation("/根据索引名称和文档id删除索引数据")
    public R<Boolean> deleteDocsById(@RequestParam(value = "docsId")  String docsId){
        return esDocService.deleteDocsById(docsId);
    }

    @PostMapping("/batchDeleteDocs")
    @ApiOperation("/批量删除索引数据")
    public R<Boolean> batchDeleteDocs(@RequestParam List<String> docsIds){
        esDocService.batchDeleteDocs(docsIds);
        return R.ok();
    }

    @PostMapping("/querySuggestions")
    @ApiOperation("根据传入条件自动补全检索")
    public void  querySuggestions(@RequestBody EsDocQueryVo esDocSelectVo){
        esDocService.querySuggestions(esDocSelectVo);
    }

}
